home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
satellit
/
pbsv004
/
pblib.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-05
|
3KB
|
197 lines
/* pblib.c 1993.8.5 */
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "pbsv.h"
/*
* < initq > initialize queue
*/
VOID initq(q)
struct stqueue *q;
{
q->head = q->tail = NULL;
}
/*
* < putq > put queue
*/
VOID putq(q,d)
struct stqueue *q;
struct stqcell *d;
{
if (q == NULL || d == NULL) {
assert(0);
}
d->next = NULL;
if (q->head == NULL) {
q->head = q->tail = d;
} else {
q->tail->next = d;
q->tail = d;
}
}
/*
* < getq > get queue
*/
struct stqcell *getq(q)
struct stqueue *q;
{
struct stqcell *r;
if (q == NULL) {
assert(0);
}
r = q->head;
if (r != NULL) {
q->head = r->next;
}
if (q->head == NULL) {
q->tail = NULL;
}
return(r);
}
/*
* < delq > delete queue
*/
VOID delq(q,d)
struct stqueue *q;
struct stqcell *d;
{
struct stqcell *d2;
struct stqueue temp;
initq(&temp);
while(d2 = getq(q)) {
if (d2 != d) {
putq(&temp,d2);
}
}
*q = temp;
}
/*
* < addq > add queue
*/
VOID addq(q1,q2)
struct stqueue *q1,*q2;
{
struct stqcell *d;
while(d = getq(q2))
putq(q1,d);
}
/*
* < cntq > count queue
*/
int cntq(q)
struct stqueue *q;
{
struct stqcell *r;
int n;
n = 0;
r = q->head;
while(r) {
r = r->next;
n++;
}
return(n);
}
/*
* < ca2ad > call -> adrs
*/
VOID ca2ad(ca,ad)
char *ca,ad[];
{
int c,i;
for (i = 0; i < 6; i++)
ad[i] = ' ' << 1;
ad[6] = 0x60;
for (i = 0; i < 7; i++) {
c = *ca++;
if (c == '\0') {
break;
} else if (isalpha(c) || isdigit(c)) { /* A-Z, 0-9 */
ad[i] = c << 1;
} else if (c == '-') {
ad[6] |= atoi(ca) << 1; /* ssid */
break;
}
}
}
/*
* < ad2ca > adrs -> call
*/
VOID ad2ca(ad,ca)
char ad[],*ca;
{
char buf[4];
int c,i;
for (i = 0; i < 6; i++) {
c = (ad[i] & 0xff) >> 1;
if (isalpha(c) || isdigit(c)) {
*ca++ = c;
} else
break;
}
*ca = '\0';
c = (ad[6] >> 1) & 0x0f;
if (c != 0) {
sprintf(buf,"-%d",c);
strcat(ca,buf);
}
}
/*
* < ckcrc > check CRC
*/
ckcrc(buf,len)
char buf[];
int len;
{
u_int gen_crc();
u_int crc;
char *p;
int i;
crc = 0;
p = &buf[17];
for(i = 17; i < len-2; i++)
crc = gen_crc(crc,*p++);
crc = gen_crc(crc, *p++); /* 1st crc byte */
if (gen_crc(crc, *p)) { /* 2nd crc byte */
printf("CRC Errors\n");
return(NG);
}
return(OK);
}
u_int gen_crc(crc,data)
u_int crc;
u_char data;
{
int y;
crc ^= ((u_int)data) << 8;
for(y=0; y < 8; y++)
if( crc & 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc <<= 1;
return(crc);
}
/* pblib.c */